<script type="text/javascript" language="javascript">
    (function($) {
        /*whatever jQuery stuff*/
        $(function(){
            jQuery.validator.addMethod("UsernameValid", function(value, element, param) {
                var returnVal = true;				
				$.ajax({
					url:'<?php echo get_url(2);?>/ajax_username_valid',
					type:'post',
					data:({
						username : value,
						old_username : '<?php echo $dataResult->username;?>'
					}),
					async:false,
					success: function(data){
						if(data==1){
							returnVal = false;
						}
					}
				});
				return returnVal;
           	}, jQuery.validator.messages.UsernameValid);
			
            jQuery.validator.addMethod("EmailValid", function(value, element, param) {
                var returnVal = true;
				$.ajax({
					url:'<?php echo get_url(2);?>/ajax_email_valid',
					type:'post',
					data:({
						email : value,
						old_email : '<?php echo $dataResult->email;?>'
					}),
					async:false,					
					success: function(data){
						if(data==1){
							returnVal = false;
						}
					}
				});
				return returnVal;
           	}, jQuery.validator.messages.EmailValid);			
						
            $("#Form").validate({
                rules: {
					group_id: "required",
                    username: {
						required: true,
						UsernameValid: true
					},
                    password: "required",
                    email: {
						required:true,
						EmailValid:true
					}
                },
                showErrors: function(errorMap, errorList){
                    var messages='';
                    for (var i = 0; i < errorList.length; i++) {					
                        messages += '- '+errorList[i].message+'\n';
                    }
                    if(messages) alert("<?php echo lang('requirement');?>: \n"+"¯¯¯¯¯¯¯¯¯¯ \n"+ messages);
                    //this.defaultShowErrors();
                } ,
                submitHandler: function(e){
					$('.ajax-loading',e).css('visibility','visible');
					form.submit();
                },
                onfocusout: false,
                onkeyup: false,
				onclick: false,						
                messages: {
					group_id: "<?php echo lang('group_name');?>",
                    username: {
						required : "<?php echo lang('username');?>",
						UsernameValid : "<?php echo lang('username_not_valid');?>"
					},
					password: "<?php echo lang('password');?>",
                    email: {
						required : "<?php echo lang('email');?>",
						EmailValid : "<?php echo lang('email_not_valid');?>"
					},					
                }
            });
			
			$('input#birthdate').simpleDatepicker({ startdate: 1950, enddate: new Date() });			
        });
    })(jQuery);
</script>
<div class="wrap">
 	<div id="icon-index" class="icon32"><br /></div><h2><?php echo ucwords(str_replace('_',' ',$this->uri->segment(1)));?> &raquo; <?php echo ucwords(str_replace('_',' ',$this->uri->segment(2)));?> &raquo; <?php echo lang($this->uri->segment(3));?></h2>
</div>
<div id="wpbody-content">
    <div class="metabox-holder" id="dashboard-widgets">
		<div class="tablenav top">
			<div class="alignleft"><input type="button" value="<?php echo lang('button_back');?>" class="button-primary" onclick="javascript:history.go(-1);"/></div>
		</div>	
            <div class="inside">			
				<form id="Form" method="post" action="" name="Form">
					<table border="0" cellspacing="0" cellpadding="0" class="form-table">
						<tbody>
						<tr>
							<th scope="row"><?php echo lang('group_name');?></th>
							<td>
								<select id="group_id" name="group_id" class="medium-text">
									<option value=""><?php echo lang('select_option');?></option>
									<?php foreach($dataGroup as $value):?>
										<option value="<?php echo $value->group_id;?>" <?php echo ($value->group_id==$dataResult->group_id ? 'selected="selected"':'');?>><?php echo $value->group_name;?></option>
									<?php endforeach;?>
								</select>
							</td>
						</tr>						
						<tr>
							<th scope="row"><?php echo lang('username');?></th>
							<td><input type="text" name="username" id="username" class="medium-text" value="<?php echo htmlspecialchars($dataResult->username, ENT_QUOTES, 'UTF-8');?>"/></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('password');?></th>
							<td><input type="password" name="password" id="password" class="medium-text" value="<?php echo $dataResult->password;?>"/></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('email');?></th>
							<td><input type="text" name="email" id="email" class="regular-text" value="<?php echo $dataResult->email;?>"/></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('status');?></th>
							<td>
								<input type="radio" name="status" value="1" <?php echo ($dataResult->status==1 ? 'checked="checked"':'');?>/> <?php echo lang('status_open');?>
								<input type="radio" name="status" value="2" <?php echo ($dataResult->status==2 ? 'checked="checked"':'');?>/> <?php echo lang('status_close');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('firstname');?></th>
							<td><input type="text" name="firstname" id="firstname" class="regular-text" value="<?php echo htmlspecialchars($dataResult->firstname, ENT_QUOTES, 'UTF-8');?>"/></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('surname');?></th>
							<td><input type="text" name="surname" id="surname" class="regular-text" value="<?php echo htmlspecialchars($dataResult->surname, ENT_QUOTES, 'UTF-8');?>"/></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('nickname');?></th>
							<td><input type="text" name="nickname" id="nickname" class="regular-text" value="<?php echo htmlspecialchars($dataResult->nickname, ENT_QUOTES, 'UTF-8');?>"/></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('phone');?></th>
							<td><input type="text" name="phone" id="phone" class="regular-text" value="<?php echo htmlspecialchars($dataResult->phone, ENT_QUOTES, 'UTF-8');?>"/></td>
						</tr>									
						<tr>
							<th scope="row">&nbsp;</th>
							<td><p class="submit"><input type="submit" value="<?php echo lang('button_edit');?>" class="button-primary" />&nbsp;<img alt="" class="ajax-loading" src="<?php echo css_asset_url('images/wpspin_light.gif'); ?>" /></p></td>
						</tr>								
						</tbody>
					</table>
					<div class="tablenav bottom"></div>
				</form>
            </div><!-- wpbody inside -->
    </div><!-- wpcontent -->
</div><!-- wpbody-content -->